package com.example.recursion;

/**
 * @Date 2022/7/9
 * @Created by Jonathan
 */
public class CardsInLine {



    /**
     * 先手
     */
    private static int f(int[] cards, int l, int r) {
        if (l == r) {
            return cards[l];
        }
        return Math.max(
                cards[l] + s(cards, l + 1, r),
                cards[r] + s(cards, l, r - 1)
        );
    }


    /**
     * 后手
     */
    private static int s(int[] cards, int i, int j) {
        if (i == j) {
            return 0;
        }
        return Math.min(
                f(cards, i + 1, j),
                f(cards, i, j - 1)
        );
    }

}
